package gui;

import gui.utils.Borders;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.JPanel;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Msg extends JPanel{
    private String message = "";
    public Msg(){super(new FlowLayout());}

    public void msg(String msg){message = msg;this.repaint();}
    public void paintComponent(Graphics g){if(bufferGraphics == null){super.paintComponent(g);}drawMessage(g);}

    private Graphics2D bufferGraphics = null;
    private Image offScreen = null;
    //use card layout and panels here to do movie!!
    private void drawMessage(Graphics g){
        final int imageHeight = 26;
        final int imageWidth = this.getWidth();
        this.setLayout(new FlowLayout(){public Dimension preferredLayoutSize(Container cont) {return (new Dimension(imageWidth, imageHeight));}});
        offScreen = this.createImage(imageWidth, imageHeight);
        bufferGraphics = (Graphics2D)offScreen.getGraphics();
        bufferGraphics.setColor(Color.red);
        bufferGraphics.setFont(Borders.getFont(Borders.GUIFONT));;
        bufferGraphics.drawString(message, 10, 24);
        g.drawImage(offScreen, 0, 0, imageWidth, imageHeight, this);
    }
}